package com.mmlc.meimei.lichengkongjian.mine;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.meimei.lichengkongjian.been.ReplaceInfoBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/12/2.
 */
public class ReplaceListAdapter extends BaseAdapter {

    List<ReplaceInfoBean> data;
    Context context;

    public ReplaceListAdapter(List<ReplaceInfoBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        MyViewHolder vh = null;
        if(convertView ==  null)
        {
            vh = new MyViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.replacegoodsinfo_item, null);
            vh.img = (ImageView)convertView.findViewById(R.id.iv_order);
            vh.delete = (ImageView)convertView.findViewById(R.id.iv_delete);
            vh.name = (TextView)convertView.findViewById(R.id.tv_goodsname);
            vh.spec = (TextView)convertView.findViewById(R.id.tv_order_specification);
            vh.price = (TextView)convertView.findViewById(R.id.tv_order_price);
            vh.num = (TextView)convertView.findViewById(R.id.tv_order_number);

            convertView.setTag(vh);
        }else{
            vh = (MyViewHolder) convertView.getTag();
        }
        vh.name.setText(data.get(position).getName());
        vh.spec.setText(data.get(position).getSpec());
        vh.price.setText("¥"+data.get(position).getPrice());
        vh.num.setText("x"+data.get(position).getCount());

        Picasso.with(context).load(data.get(position).getUrl()).into(vh.img);

        return convertView;
    }

    public  class MyViewHolder{

        public ImageView img ;
        public ImageView delete;
        public TextView name ;
        public TextView spec ;
        public TextView price ;
        public TextView num ;

    }
}
